/**
 * Created by zhanhun on 16/8/11.
 */

$(function () {

    $('#main-menu').metisMenu();

    $(window).bind("load resize", function () {
        if ($(this).width() < 768) {
            $('div.sidebar-collapse').addClass('collapse')
        } else {
            $('div.sidebar-collapse').removeClass('collapse')
        }
    });
    // 集群渲染
    $.getJSON($.getClustersUrl(), function (data) {
        var select = $('#biz-es-list');
        select.html('');
        for (var i in data.content) {
            select.append(
                '<option>' + data.content[i] + '</option>'
            );
        }
    });

    $('#biz-es-list').change(function () {
        var es = $(this).val();
        if (es) {
            $.getJSON($.getIndicesUrl(), {
                cluster: es
            }, function (data) {
                var tab = $('.biz-index-tab');
                tab.html('');
                for (var i in data.content) {
                    var html = '<tr>'+
                    '<td>' + i +'</td>' +
                    '<td>' + data.content[i].index + '</td>' +
                    '<td>' + data.content[i].aliases.join(',') + '</td>' +
                    '<td>' +
                    '<a href="' + $.getIndexInfoUrl(es, data.content[i].index) + '" class="btn btn-info btn-sm J-index-info">详情</a>' +
                        '&nbsp;' +
                        '<a href="javascript:void(0)" data-cluster="' + es + '" data-index="' + data.content[i].index + '" class="btn btn-danger btn-sm J-index-del">删除</a>' +
                        '</td>' +
                        '</tr>';
                    tab.append(html);
                }
            });
        }
    });

});
